package com.xyy.saas.payment.service.impl;

import com.xyy.saas.payment.dao.mapper.SeparateSummaryMapper;
import com.xyy.saas.payment.dao.model.SeparateSummary;
import com.xyy.saas.payment.service.SeparateSummaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Service
public class SeparateSummaryServiceImpl implements SeparateSummaryService {

    @Autowired
    private SeparateSummaryMapper separateSummaryMapper;

    @Override
    public List<SeparateSummary> selectByParam(SeparateSummary param) {
        if(null == param) {
            return new ArrayList<>();
        }
        return separateSummaryMapper.selectByParam(param);
    }

    @Override
    public SeparateSummary selectBySeparateNo(String separateNo) {
        if(StringUtils.isEmpty(separateNo)) {
            return null;
        }
        return separateSummaryMapper.selectBySeparateNo(separateNo);
    }

    @Override
    public SeparateSummary selectByBusinessOrderNo(String businessOrderNo) {
        if(StringUtils.isEmpty(businessOrderNo)) {
            return null;
        }
        return separateSummaryMapper.selectByBusinessOrderNo(businessOrderNo);
    }

    @Override
    public int insert(SeparateSummary entity) {
        if(null != selectBySeparateNo(entity.getSeparateNo()) || null != selectByBusinessOrderNo(entity.getBusinessOrderNo())) {
            return 0;
        }
        return separateSummaryMapper.insert(entity);
    }

    @Override
    public int updateById(SeparateSummary entity) {
        return separateSummaryMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public int deleteById(Long id) {
        return separateSummaryMapper.deleteByPrimaryKey(id);
    }
}
